using UnityEngine;

public class BgController : MonoBehaviour
{
    public GameObject bgImg;
    int ScrHeight, ScrWidth;
    bool isGetScreenSize = false;
    public void SetBgSize(int OriWidth, int OriHeight)
    {
        if(!isGetScreenSize)
        {
            ScrHeight = Screen.height;
            ScrWidth = Screen.width;
            isGetScreenSize = true;
        }
        double r = (double)OriWidth / (double)OriHeight;
        if (Screen.width < Screen.height * r)
        {
            bgImg.GetComponent<RectTransform>().sizeDelta = new Vector2((int)(ScrHeight * r), ScrHeight);
        }
        else
        {
            bgImg.GetComponent<RectTransform>().sizeDelta = new Vector2(ScrWidth, ScrWidth * OriHeight / OriWidth);
        }
    }
}